package vip.xiaonuo.core.indexMenu;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.core.indexMenu.entity.IndexDataDetail;
import vip.xiaonuo.core.indexMenu.entity.MenuIndex;
import vip.xiaonuo.core.indexMenu.entity.MenuIndexAdd;
import vip.xiaonuo.core.indexMenu.entity.MenuIndexShowDto;
import vip.xiaonuo.core.indexMenu.mapper.IndexDataDetailMapper;
import vip.xiaonuo.core.indexMenu.service.CompanyIndexService;


import javax.validation.Valid;
import java.util.List;

@Api(tags = "系统首页相关")
@RestController
public class CompanyIndexController {
    @Autowired
    private CompanyIndexService companyIndexService;
    @Autowired
    private IndexDataDetailMapper indexDataDetailMapper;

    @ApiOperation("获取首页菜单")
    @CommonLog("获取首页菜单")
    @GetMapping("/menuIndex/get")
    public CommonResult<List<MenuIndex>> menuIndexGet(String name) {
        return CommonResult.data(companyIndexService.menuIndexGet(name));
    }

    @ApiOperation("新增or编辑首页菜单")
    @CommonLog("新增or编辑首页菜单")
    @PostMapping("/menuIndex/add")
    public CommonResult<List<MenuIndex>> menuIndexAdd(@RequestBody @Valid MenuIndexAdd menuIndexAdd) {
        companyIndexService.menuIndexAdd(menuIndexAdd);
        return CommonResult.ok();
    }
    @ApiOperation("删除首页菜单")
    @CommonLog("删除首页菜单")
    @PostMapping("/menuIndex/del")
    public CommonResult<List<MenuIndex>> menuIndexDel(@RequestBody  MenuIndex menuIndex) {
        companyIndexService.menuIndexDel(menuIndex.getId());
        return CommonResult.ok();
    }

    @ApiOperation("获取某个页面的数据（多条或者一条）")
    @CommonLog("获取某个页面的数据（多条或者一条）")
    @GetMapping("/menuIndex/getData")
    public CommonResult<PageInfo<IndexDataDetail>> getData(@ApiParam("查看第几页") Integer current, @ApiParam("每页多少条") Integer size, Integer id){
        return CommonResult.data(companyIndexService.getIndexData(current,size,id));
    }

    @ApiOperation("新增页面数据（单条）")
    @CommonLog("新增页面数据（单条）")
    @PostMapping("/menuIndex/addData")
    public CommonResult<String> addData(@RequestBody IndexDataDetail indexDataDetail){
        companyIndexService.addData(indexDataDetail);
        return CommonResult.ok();
    }

    @ApiOperation("修改页面数据")
    @PostMapping("/menuIndex/updateData")
    public CommonResult updateData(@RequestBody IndexDataDetail indexDataDetail){
        companyIndexService.updateData(indexDataDetail);
        return CommonResult.ok();
    }

    @ApiOperation("删除页面数据")
    @GetMapping("/menuIndex/deleteData")
    public CommonResult deleteData(Integer id){
        companyIndexService.deleteData(id);
        return CommonResult.ok();
    }

    @ApiOperation("获取首页数据")
    @GetMapping("/menuIndex/homePageData")
    public CommonResult<List<MenuIndexShowDto>> getHomePageData(){
        return CommonResult.data(companyIndexService.getMenuIndexShowDto());
    }
    
}
